﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using BUSINESS_OBJECT;

namespace CRM.customer
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        Appmntcls appmt = new Appmntcls();
        Custcls cust = new Custcls();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt = appmt.GetRecords(-99, -99, "", "", -99, "", Convert.ToDateTime("1/1/1800"), false, " and ");
                GridView1.DataSource = dt;
                GridView1.DataBind();

                DataTable dt1 = cust.GetRecords(-99, "", "", "", "", -99, "", Convert.ToDateTime("1/1/1800"), -99,"", "", "", "","","", false, " and ");
                DropDownList1.DataSource = dt1;
                DropDownList1.DataTextField = "COMPANY_NAME";
                DropDownList1.DataValueField = "CID";
                DropDownList1.DataBind();


            }
        }

        //protected void Button1_Click(object sender, EventArgs e)
        //{
        // appmt.ID = -99;
        //appmt.CID = -99;
        //appmt.COMPANY_PERSON_NAME = Txtpname.Text;
        //appmt.COMPANY_ADDRESS = txtcpadd.Text;
        //appmt.PHONE_NO = Convert.ToInt64(Txtphone.Text);
        //appmt.REASON = Txtreason.Text;
        //appmt.DATE =  Convert.ToDateTime( Txtdate.Text);
        //appmt.ISDELETED = false;
        //appmt.SaveRecords();
        //Response.Redirect("~/customer/home.aspx");


        //}
        protected void btDelete_Command(object sender, CommandEventArgs e)
        {
            DataTable dt = appmt.GetRecords(Convert.ToInt64(e.CommandArgument.ToString()), -99, "", "", -99, "", Convert.ToDateTime("1/1/1800"), false, " and ");
            appmt.ID = Convert.ToInt64(dt.Rows[0]["ID"].ToString());
            appmt.CID = Convert.ToInt64(dt.Rows[0]["CID"].ToString());
            appmt.COMPANY_PERSON_NAME = dt.Rows[0]["COMPANY_PERSON_NAME"].ToString();
            appmt.COMPANY_ADDRESS = dt.Rows[0]["COMPANY_ADDRESS"].ToString();
            appmt.PHONE_NO = Convert.ToInt64(dt.Rows[0]["PHONE_NO"].ToString());
            appmt.REASON = dt.Rows[0]["REASON"].ToString();
            appmt.DATE = Convert.ToDateTime(dt.Rows[0]["DATE"].ToString());
            appmt.ISDELETED = true;
            appmt.SaveRecords();
            Response.Redirect("Appmnt.aspx");

        }






        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btEdit_DataBinding(object sender, EventArgs e)
        {
            //DataTable dt =appmt.GetRecords(Convert.ToInt64( e.CommandArgument.ToString()),  -99, "", "", -99, "", Convert.ToDateTime("1/1/1800"), false, " and ");
            //appmt.ID = Convert.ToInt64(dt.Rows[0]["ID"].ToString());
            //appmt.CID = Convert.ToInt64(dt.Rows[0]["CID"].ToString());
            //appmt.COMPANY_PERSON_NAME = dt.Rows[0]["COMPANY_PERSON_NAME"].ToString();
            //appmt.COMPANY_ADDRESS = dt.Rows[0]["COMPANY_ADDRESS"].ToString();
            //appmt.PHONE_NO = Convert.ToInt64(dt.Rows[0]["PHONE_NO"].ToString());
            //appmt.REASON = dt.Rows[0]["REASON"].ToString();
            //appmt.DATE = Convert.ToDateTime(dt.Rows[0]["DATE"].ToString());
            //appmt.ISDELETED = true;
            //appmt.SaveRecords();
        }

        protected void btndone_Click(object sender, EventArgs e)
        {

            appmt.ID = -99;
            appmt.CID = Convert.ToInt64(DropDownList1.SelectedValue.ToString());
            appmt.COMPANY_PERSON_NAME = Txtpname.Text;
            appmt.COMPANY_ADDRESS = txtcpadd.Text;
            appmt.PHONE_NO = Convert.ToInt64(Txtphone.Text);
            appmt.REASON = Txtreason.Text;
            appmt.DATE = Convert.ToDateTime(Txtdate.Text);
            appmt.ISDELETED = false;
            appmt.SaveRecords();
            Response.Redirect("Appmnt.aspx");

        }

        protected void btEdit_Command(object sender, CommandEventArgs e)
        {


            DataTable dt = appmt.GetRecords(Convert.ToInt64(e.CommandArgument.ToString()), -99, "", "", -99, "", Convert.ToDateTime("1/1/1800"), false, " and ");
            txtid.Text = dt.Rows[0]["ID"].ToString();
            DropDownList1.SelectedValue = dt.Rows[0]["CID"].ToString();
            Txtpname.Text = dt.Rows[0]["COMPANY_PERSON_NAME"].ToString();
            txtcpadd.Text = dt.Rows[0]["COMPANY_ADDRESS"].ToString();
            Txtphone.Text = dt.Rows[0]["PHONE_NO"].ToString();
            Txtreason.Text = dt.Rows[0]["REASON"].ToString();
            Txtdate.Text = dt.Rows[0]["DATE"].ToString();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
        }

        protected void Btupdate_Click(object sender, EventArgs e)
        {
           appmt.ID = Convert.ToInt64(txtid.Text);
           appmt.CID = Convert.ToInt64(DropDownList1.SelectedValue.ToString());
            appmt.COMPANY_PERSON_NAME = Txtpname.Text;
            appmt.COMPANY_ADDRESS = txtcpadd.Text;
            appmt.PHONE_NO = Convert.ToInt64(Txtphone.Text);
            appmt.REASON = Txtreason.Text;
            appmt.DATE = Convert.ToDateTime(Txtdate.Text);
            appmt.ISDELETED = false;
            appmt.SaveRecords();
            Response.Redirect("Appmnt.aspx");
        }


    }


}
